package org.shopping.web.commodity;

import org.shopping.service.commodity.impl.CommodityServiceImpl;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;

@WebServlet(name = "DeleteCommodityController", value = "/DeleteCommodityController")
public class DeleteCommodityController extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // 获取被删除的商品id
        String cidForm = request.getParameter("cid");
        // 调用service层方法判断是否删除成功
        CommodityServiceImpl commodityService = new CommodityServiceImpl();
        boolean flag = commodityService.deleteCommodity(cidForm);
        if (flag) {
            // 删除成功
            response.sendRedirect(request.getContextPath() + "/index.jsp");
        }
    }
}
